var mysql = require("mysql");

var pool = mysql.createPool({
  host: "47.90.157.187",
  user: "root",
  password: "Earnplaycenter123.",
  database: "intelligent_health",
  port: 3306,
  charset: "utf8mb4",
});

//callback为回调方法
async function queryDataBySQL(sql, callback) {
  return await new Promise((reslove, reject) => {
    pool.getConnection(function (err, connection) {
      connection.query(sql, function (err, result) {
        if (err) {
          reject(err);
        } else {
          if (callback) {
            callback(result);
          }
          reslove(result);
        }
      });
      connection.release();
      //console.log("close mysql connection");
    });
  });
}

module.exports = {
  queryDataBySQL,
};
